<?php

class GoodsTag{
	public $tag = array(
		'channel'=>array('block'=>1,'level'=>4)//设置block标签为块级标签，支持四层嵌套  
		);
	//栏目标签 
	public function _channel($attr,$content){
		$cid = $attr['cid'];
		$php=<<<str
		<?php
		\$Model = M('category');
		\$result = \$Model->where("pid=$cid")->all();
		foreach(\$result as \$field):
			\$field['url']=U('category',array('cid'=>\$field['cid']));
		?>
str;
	$php.=$content;
	$php.='<?php endforeach;?>';
	return $php;
	}

	public function _goods($attr,$content){
		$row=$attr['row'];
		$cid =$attr['cid'];
		$flag=isset($attr['flag'])?$attr['flag']:0;
		$php=<<<str
		<?php
		\$flag=$flag;
		\$row=$row;
		\$cid = explode(',',str_replace(' ','',"$cid"));
		\$Model=M('goods');
		if($flag){
			\$result=\$Model->limit(\$row)->where(array('cid'=>\$cid,'flag'=>\$flag))->all();
		}else{
			\$result=\$Model->limit(\$row)->where(array('cid'=>\$cid))->all();
		}
		foreach(\$result as \$field):
			\$field['url']=U('content',array('gid'=>\$field['gid']));
			\$field['index_pic']="__ROOT__/".\$field['index_pic'];
			\$field['price']=\$field['price'];
			\$field['cid']=\$field['cid'];
		?>
str;
		$php.=$content;
		$php.='<?php endforeach;?>';
		return $php;
	}

	public function _g($attr,$content){
		$gid =$attr['gid'];
		$php=<<<str
		<?php
		\$gid = explode(',',str_replace(' ','',"$gid"));
		\$Model=M('goods');
		\$result=\$Model->where(array('gid'=>\$gid))->all();
		foreach(\$result as \$field):
			\$field['url']=U('content',array('gid'=>\$field['gid']));
			\$field['index_pic']="__ROOT__/".\$field['index_pic'];
		?>
str;
		$php.=$content;
		$php.='<?php endforeach;?>';
		return $php;
	}

	public function _oods($attr,$content){
		$row=$attr['row'];
		$cid =$attr['cid'];
		$flag=$attr['flag'];
		$php=<<<str
		<?php
		\$flag=$flag;
		\$row=$row;
		\$cid = explode(',',str_replace(' ','',"$cid"));
		\$Model=M('goods');
		\$result=\$Model->limit(\$row)->where(array('cid'=>\$cid,'flag'=>\$flag))->all();
		foreach(\$result as \$field):
			\$field['url']=U('content',array('gid'=>\$field['gid']));
			\$field['index_pic']="__ROOT__/".\$field['index_pic'];
			\$field['price']=\$field['price'];
			\$field['cid']=\$field['cid'];
		?>
str;
		$php.=$content;
		$php.='<?php endforeach;?>';
		return $php;
	}








}